package com.jet.merchant.remote.office;

import com.jet.core.exception.CustomException;
import com.jet.core.result.ResultJson;
import com.jet.merchant.remote.office.vo.IndustryAttrVo;
import com.jet.merchant.remote.office.vo.MerchantIndustryVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author dcl
 * @since 2025/2/21 17:30
 */
@Service
@Slf4j
public class MerchantOfficeRemote {

    private final MerchantOfficeRemoteFeign merchantOfficeRemoteFeign;

    public MerchantOfficeRemote(MerchantOfficeRemoteFeign merchantOfficeRemoteFeign) {
        this.merchantOfficeRemoteFeign = merchantOfficeRemoteFeign;
    }

    public MerchantIndustryVo getMerchantIndustry(long merchantNo) {
        ResultJson<MerchantIndustryVo> result = merchantOfficeRemoteFeign.getMerchantIndustry(merchantNo);
        if (result.getCode() != ResultJson.ok().getCode()) {
            log.error("获取店铺功能信息异常，{}", result.getMsg());
            throw new CustomException(result.getMsg());
        }
        return result.getData();
    }

    public List<IndustryAttrVo> getMerchantIndustryAbility(long merchantNo) {
        ResultJson<List<IndustryAttrVo>> result = merchantOfficeRemoteFeign.getMerchantAbility(merchantNo);
        if (result.getCode() != ResultJson.ok().getCode()) {
            log.error("获取店铺功能信息异常，{}", result.getMsg());
            throw new CustomException(result.getMsg());
        }
        return result.getData();
    }

    public void industryTrial(long merchantNo, long storeNo, String accountId) {
        ResultJson<Void> result = merchantOfficeRemoteFeign.industryTrial(merchantNo, storeNo, accountId);
        if (result.getCode() != ResultJson.ok().getCode()) {
            log.error("店铺开通试用版异常，{}", result.getMsg());
            throw new CustomException(result.getMsg());
        }
    }
}
